package org.jeecg.modules.rental.service.impl;


import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.rental.entity.IotTerminalTemp;
import org.jeecg.modules.rental.entity.RentalEBike;
import org.jeecg.modules.rental.mapper.IotTerminalTempMapper;
import org.jeecg.modules.rental.mapper.RentalEBikeMapper;
import org.jeecg.modules.rental.service.IIotTerminalTempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import static org.apache.commons.lang3.StringUtils.isNumeric;

/**
 * @Description: 终端上线临时
 * @Author: jeecg-boot
 * @Date:   2024-12-24
 * @Version: V1.0
 */
@Service
public class IotTerminalTempServiceImpl extends ServiceImpl<IotTerminalTempMapper, IotTerminalTemp> implements IIotTerminalTempService {

    @Autowired
    RentalEBikeMapper rentalEBikeMapper;


    @Override
    public Result<String> syncIot(IotTerminalTemp iotTerminalTemp) {
        RentalEBike rentalEBike=new RentalEBike();


        // 过滤非数字和空的数据
        if (!isNumeric(iotTerminalTemp.getSn()) ||!isNumeric(iotTerminalTemp.getImei())) {
            return Result.error("无法同步非中控设备");
        }
        rentalEBike.setCarCode(iotTerminalTemp.getImei());
        // 获取手机号并进行处理
        String phone = iotTerminalTemp.getImei(); // 假设手机号为 imei
        if (phone.length() > 12) {
            phone = phone.substring(3); // 截掉前面 3 位数字
        }
        rentalEBike.setPhone(phone);
        rentalEBike.setCustomCode("new_car_add");
        rentalEBikeMapper.insert(rentalEBike);
        return Result.OK("同步成功");
    }
}
